<?php

namespace common\models\Fenhui;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Fenhui\Fenhui;

/**
 * FenhuiSearch represents the model behind the search form about `common\models\Fenhui\Fenhui`.
 */
class FenhuiSearch extends Fenhui
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'userid', 'youbian', 'qiyerenshu', 'jingjileixing', 'qiyexingzhi', 'flag'], 'integer'],
            [['grade', 'qiyemingcheng', 'farendaibiao', 'qiyedizhi', 'farentel', 'farenmobile', 'farenfax', 'contact', 'tel', 'mobile', 'fax', 'qiyewangzhi', 'email', 'shigongzizhi', 'certificatenumber', 'zhucezijin', 'konggugudong', 'qiyepinpai', 'product', 'qiyejianjie'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Fenhui::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'userid' => $this->userid,
            'youbian' => $this->youbian,
            'qiyerenshu' => $this->qiyerenshu,
            'jingjileixing' => $this->jingjileixing,
            'qiyexingzhi' => $this->qiyexingzhi,
            'flag' => $this->flag,
        ]);

        $query->andFilterWhere(['like', 'grade', $this->grade])
            ->andFilterWhere(['like', 'qiyemingcheng', $this->qiyemingcheng])
            ->andFilterWhere(['like', 'farendaibiao', $this->farendaibiao])
            ->andFilterWhere(['like', 'qiyedizhi', $this->qiyedizhi])
            ->andFilterWhere(['like', 'farentel', $this->farentel])
            ->andFilterWhere(['like', 'farenmobile', $this->farenmobile])
            ->andFilterWhere(['like', 'farenfax', $this->farenfax])
            ->andFilterWhere(['like', 'contact', $this->contact])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'mobile', $this->mobile])
            ->andFilterWhere(['like', 'fax', $this->fax])
            ->andFilterWhere(['like', 'qiyewangzhi', $this->qiyewangzhi])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'shigongzizhi', $this->shigongzizhi])
            ->andFilterWhere(['like', 'certificatenumber', $this->certificatenumber])
            ->andFilterWhere(['like', 'zhucezijin', $this->zhucezijin])
            ->andFilterWhere(['like', 'konggugudong', $this->konggugudong])
            ->andFilterWhere(['like', 'qiyepinpai', $this->qiyepinpai])
            ->andFilterWhere(['like', 'product', $this->product])
            ->andFilterWhere(['like', 'qiyejianjie', $this->qiyejianjie]);

        return $dataProvider;
    }
    //再审核
    public function unchecksearch($params)
    {
        $query = Fenhui::find()->andWhere(['flag'=>Fenhui::STATUS_DELETED])->orderBy('id desc');
        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'flag' => $this->flag,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'grade', $this->grade])
            ->andFilterWhere(['like', 'qiyemingcheng', $this->qiyemingcheng])
            ->andFilterWhere(['like', 'farendaibiao', $this->farendaibiao])
            ->andFilterWhere(['like', 'qiyedizhi', $this->qiyedizhi])
            ->andFilterWhere(['like', 'farentel', $this->farentel])
            ->andFilterWhere(['like', 'farenmobile', $this->farenmobile])
            ->andFilterWhere(['like', 'farenfax', $this->farenfax])
            ->andFilterWhere(['like', 'contact', $this->contact])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'mobile', $this->mobile])
            ->andFilterWhere(['like', 'fax', $this->fax])
            ->andFilterWhere(['like', 'qiyewangzhi', $this->qiyewangzhi])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'shigongzizhi', $this->shigongzizhi])
            ->andFilterWhere(['like', 'certificatenumber', $this->certificatenumber])
            ->andFilterWhere(['like', 'zhucezijin', $this->zhucezijin])
            ->andFilterWhere(['like', 'konggugudong', $this->konggugudong])
            ->andFilterWhere(['like', 'qiyepinpai', $this->qiyepinpai])
            ->andFilterWhere(['like', 'product', $this->product])
            ->andFilterWhere(['like', 'qiyejianjie', $this->qiyejianjie]);

        return $dataProvider;
    }
            /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    //分会待审核
    public function waitchecksearch($params)
    {
        $query = Fenhui::find()->andWhere(['flag'=>Fenhui::STATUS_ACTIVE])->orderBy('id desc');
        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'flag' => $this->flag,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'grade', $this->grade])
            ->andFilterWhere(['like', 'qiyemingcheng', $this->qiyemingcheng])
            ->andFilterWhere(['like', 'farendaibiao', $this->farendaibiao])
            ->andFilterWhere(['like', 'qiyedizhi', $this->qiyedizhi])
            ->andFilterWhere(['like', 'farentel', $this->farentel])
            ->andFilterWhere(['like', 'farenmobile', $this->farenmobile])
            ->andFilterWhere(['like', 'farenfax', $this->farenfax])
            ->andFilterWhere(['like', 'contact', $this->contact])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'mobile', $this->mobile])
            ->andFilterWhere(['like', 'fax', $this->fax])
            ->andFilterWhere(['like', 'qiyewangzhi', $this->qiyewangzhi])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'shigongzizhi', $this->shigongzizhi])
            ->andFilterWhere(['like', 'certificatenumber', $this->certificatenumber])
            ->andFilterWhere(['like', 'zhucezijin', $this->zhucezijin])
            ->andFilterWhere(['like', 'konggugudong', $this->konggugudong])
            ->andFilterWhere(['like', 'qiyepinpai', $this->qiyepinpai])
            ->andFilterWhere(['like', 'product', $this->product])
            ->andFilterWhere(['like', 'qiyejianjie', $this->qiyejianjie]);

        return $dataProvider;
    }
    //已审核
    public function checksearch($params)
    {
        $query = Fenhui::find()->andWhere(['<', 'flag', 2])->orderBy('id desc');

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'flag' => $this->flag,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'grade', $this->grade])
            ->andFilterWhere(['like', 'qiyemingcheng', $this->qiyemingcheng])
            ->andFilterWhere(['like', 'farendaibiao', $this->farendaibiao])
            ->andFilterWhere(['like', 'qiyedizhi', $this->qiyedizhi])
            ->andFilterWhere(['like', 'farentel', $this->farentel])
            ->andFilterWhere(['like', 'farenmobile', $this->farenmobile])
            ->andFilterWhere(['like', 'farenfax', $this->farenfax])
            ->andFilterWhere(['like', 'contact', $this->contact])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'mobile', $this->mobile])
            ->andFilterWhere(['like', 'fax', $this->fax])
            ->andFilterWhere(['like', 'qiyewangzhi', $this->qiyewangzhi])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'shigongzizhi', $this->shigongzizhi])
            ->andFilterWhere(['like', 'certificatenumber', $this->certificatenumber])
            ->andFilterWhere(['like', 'zhucezijin', $this->zhucezijin])
            ->andFilterWhere(['like', 'konggugudong', $this->konggugudong])
            ->andFilterWhere(['like', 'qiyepinpai', $this->qiyepinpai])
            ->andFilterWhere(['like', 'product', $this->product])
            ->andFilterWhere(['like', 'qiyejianjie', $this->qiyejianjie]);

        return $dataProvider;
    }
}
